package org.arch_learn.boot.utils;

import java.lang.annotation.Annotation;
import java.util.Arrays;

public class ClassUtil {
    public static Boolean ifAnnotationPresented(Class sourceClazz, Class targetClazz) {
        Annotation[] annotations = sourceClazz.getAnnotations();
        return Arrays.stream(annotations).anyMatch(a -> {
            if (a.getClass().equals(targetClazz)) return true;
            Annotation[] parentAnnotations = a.getClass().getAnnotations();
            return Arrays.stream(parentAnnotations)
                    .anyMatch(p -> ifAnnotationPresented(p.getClass(), targetClazz));
        });
    }
}
